﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DocumentEdit.aspx.cs" Inherits="MvcProject.Pages.WebOffice.DocumentEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
            .button
            {
                border-right: black 1pt solid;
                border-top: black 1pt solid;
                font-size: 9pt;
                border-left: black 1pt solid;
                width: 80px;
                color: #000000;
                border-bottom: black 1pt solid;
                font-family: '宋体';
                background-color: menu;
                text-decoration: none;
            }
        </style>

    <script type="text/javascript">
        function StatusMsg(mString) {
            try {
                var StatusBar = document.getElementById('StatusBar');
                StatusBar.innerText = mString;
            }
            catch (e) { }
        }
        function Load() {
            var objWebOffice = document.getElementById('WebOffice1');
            objWebOffice.WebUrl = 'OfficeServer.aspx';
            objWebOffice.RecordID = "<%=RecordID %>";
            objWebOffice.Template = '<%=Template %>';
            objWebOffice.FileName = "<%=RecordID %><%=FileType %>";
            objWebOffice.FileType = "<%=FileType %>";
            objWebOffice.EditType = '1';
            objWebOffice.UserName = "<%=UserName %>";
            objWebOffice.Command = "<%=COMMAND %>";
            objWebOffice.WebSetMsgByName("COMMAND", "<%=COMMAND %>");
            <%if(COMMAND=="INSERTFILE"){ %>
            if (objWebOffice.WebLoadTemplate()){
	        }else{}
            <%}else{ %>
            objWebOffice.WebOpen();  	//打开该文档  
            <%}%>
            //以下属性可以不要
            objWebOffice.ShowMenu = "1";
            objWebOffice.AppendMenu("1", "打开本地文件(&L)");
            objWebOffice.AppendMenu("2", "保存本地文件(&S)");
            //objWebOffice.AppendMenu("3","保存远程文件(&U)");
            //objWebOffice.AppendMenu("4","-");
            //objWebOffice.AppendMenu("5","签名印章(&Q)");
            //objWebOffice.AppendMenu("6","验证签章(&Y)");
            //objWebOffice.AppendMenu("7","-");
            //objWebOffice.AppendMenu("8","保存版本(&B)");
            //objWebOffice.AppendMenu("9","打开版本(&D)");
            //objWebOffice.AppendMenu("10","-");
            //objWebOffice.AppendMenu("11","测试菜单一(&X)");
            //objWebOffice.AppendMenu("12","测试菜单二(&Z)");
            objWebOffice.AppendMenu("13", "-");
            objWebOffice.AppendMenu("14", "保存并退出(&E)");
            objWebOffice.AppendMenu("15", "-");
            objWebOffice.AppendMenu("16", "打印文档(&P)");
            objWebOffice.DisableMenu("宏;选项;帮助");  //禁止菜单	
            objWebOffice.Caption = "杭州诺泰建筑工程有限公司专用"; //客户自己的名字或空;		
            objWebOffice.WebObject.ActiveWindow.ActivePane.View.Type = 3;
            StatusMsg(objWebOffice.Status);
        }
        function UnLoad() {
            try {
                var objWebOffice = document.getElementById('WebOffice1');
                objWebOffice.WebClose();
            }
            catch (e) { alert(e); }
        }
        function WebProtect(value) {
            try {
                var objWebOffice = document.getElementById('WebOffice1');
                objWebOffice.WebSetProtect(value, '');
            }
            catch (e) { alert(e); }
        }
        function SaveFileToLocal() {
            try {
                var objWebOffice = document.getElementById('WebOffice1');
                objWebOffice.WebSaveLocal();
            }
            catch (e) { alert(e); }
        }
        function ShowRevision(mObject) {
            var objWebOffice = document.getElementById('WebOffice1');
            if (objWebOffice.WebObject.Application.ActiveDocument.ShowRevisions == false) {
                objWebOffice.WebObject.Application.ActiveDocument.ShowRevisions = true;
                objWebOffice.EditType = '2';
                mObject.src = 'Images/hiddenTrace.gif';
                mObject.title = '隐藏痕迹';
            }
            else {
                objWebOffice.WebObject.Application.ActiveDocument.ShowRevisions = false;
                mObject.src = 'Images/showTrace.gif';
                mObject.title = '显示痕迹';
            }
        }
        //作用：获取文档页数
        function WebDocumentPageCount() {
            var intPageTotal;
            var objWebOffice = document.getElementById('WebOffice1');
            intPageTotal = objWebOffice.WebObject.Application.ActiveDocument.BuiltInDocumentProperties(14);
            alert("文档页总数：" + intPageTotal);
        }	
        function Change() {
            var objWebOffice = document.getElementById('WebOffice1');
            if (objWebOffice.WebOffice.width > 1) {
                objWebOffice.width = 1;
                objWebOffice.height = 1;
            }
            else {
                objWebOffice.width = 650;
                objWebOffice.height = 500;
            }
        }
        function OpenLocalDocument() {
            try {
                var objWebOffice = document.getElementById('WebOffice1');
                objWebOffice.WebOpenLocal();
            }
            catch (e) { alert(e); }
        }
        function PrintSetting() {
            try {
                var objWebOffice = document.getElementById('WebOffice1');
                objWebOffice.WebObject.Application.Dialogs(88).Show();
            }
            catch (e) { alert('查看打印机是否已联机'); }
        }
        function DocumentSave() {
            var objWebOffice = document.getElementById('WebOffice1');
            if (!objWebOffice.WebSave()) {
                StatusMsg(objWebOffice.Status);
                return true;
            }
            else {
                StatusMsg(objWebOffice.Status);
                return false;
            }
        }
        function WebOpenPageSetup() {
            var objWebOffice = document.getElementById('WebOffice1');
            if (objWebOffice.FileType == '.doc') {
                objWebOffice.Application.Dialogs(178).Show();
            }
            else {
                objWebOffice.Application.Dialogs(7).Show();
            }
        }
        function DealOnload() {
            var funcStr = "window.setTimeout(Load, 1);";
            var window_onload = new Function(funcStr);
            window.attachEvent('onload', window_onload);
        }
        //作用：保存文档
        function SaveDocument() {
            var objWebOffice = document.getElementById('WebOffice1');
			objWebOffice.WebShow(true);
			if (objWebOffice.EditType == "0")
			{
				alert("你在查看状态，不能保存!");
				return false;
			}
			if (!objWebOffice.WebSave())
			{
				StatusMsg(objWebOffice.Status);
				return false;
			}
			else
			{
				StatusMsg(objWebOffice.Status);
				return true;
			}
		}
        //DealOnload()
    </script>
    <script  type="text/vbscript">
    Function FillTemplate()
        Set objWord = PrintFullScreen.WebOffice2.WebObject.Application
        Set objDocument = objWord.ActiveDocument
        With objDocument
             If .Fields.Count>0 Then
             For i=1 to .Fields.Count
             .Fields.item(i).ShowCodes = False
             Next
             .Variables.Add "CON_RecordID","701a8725-413a-440c-8ed7-fff61892ca3a "
             .Variables.Add "CON_Emergency"," "
             objDocument.Fields.Update
             End If
         End With
     End Function
 </script>
</head>
<body onload="Load()" onunload="UnLoad()">
    <form id="form1" runat="server">
<div>
        <table id="WebOfficetable" align="center" border="0" width="90%" style=''>
            <tr>
                <td width="90%">
                    <table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" align="center" class="TBStyle">
                        <tr>
                            <td width="100%">
                                <img title="保存" alt="保存" onclick="SaveDocument()" src='Images/save.gif'/>
                                <img id='xianshi' style='cursor: hand' onclick="ShowRevision(this)" src='Images/hiddenTrace.gif'
                                    title='隐藏痕迹' alt="隐藏痕迹"/>&nbsp;&nbsp;
                                <img id="saveas" style='cursor: hand' onclick="SaveFileToLocal()"
                                        src='Images/saveas.gif' title='另存为' alt="另存为"/>&nbsp;&nbsp;
                                <img id="Img1" style='cursor: hand' onclick="OpenLocalDocument()"
                                        src='Images/saveas.gif' title='打开本地文件' alt="打开本地文件"/>&nbsp;&nbsp;
                                <img id="pagesetup" style='cursor: hand' onclick="WebOpenPageSetup()" src='Images/pagesetting.gif'
                                            title='页面设置' alt="页面设置"/>&nbsp;&nbsp;
                                <img id="prints" style='cursor: hand' onclick="PrintSetting()"
                                                src='Images/printsetting.gif' title='打印设置' alt="打印设置"/>
                                <input type="button" class="button" value="文档页数" onclick="WebDocumentPageCount()"/>
                                <label id="StatusBar"></label>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" width="100%">
                                <object id='WebOffice1' width='100%' height='800' classid='clsid:23739A7E-5741-4D1C-88D5-D50B18F7C347'
                                    codebase='WOCX/iWebOffice2003.ocx#version=6,5,6,0'>
                                </object>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
